
import Class.Conexion;
import java.sql.*;

/*
 * VistaCliente.java
 *
 * Created on 5 de abril de 2008, 16:55
 */
import javax.swing.JDialog;
import javax.swing.JFrame;




/**
 *
 * @author  Magaña
 */
public class VistaCliente extends javax.swing.JFrame {
    
       Control miControl;
    /** Creates new form Principal */
    public VistaCliente() {
        miControl = new Control(this);
        initComponents();       
        Conexion con = new Conexion("jdbc:odbc:DSNblockbuster","sa","sadb");
        tblMovies.setModel(con.executeQuery("SELECT Titulo, Genero, Cantidad FROM Peliculas"));
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        txtTitle = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        btnBuscar = new javax.swing.JButton();
        cmbGenero = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblMovies = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel2.setLayout(new java.awt.GridLayout(2, 5));
        jPanel2.add(txtTitle);

        jLabel1.setText("Nombre");
        jPanel2.add(jLabel1);

        btnBuscar.setText("Buscar");
        btnBuscar.addActionListener(miControl);
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });
        jPanel2.add(btnBuscar);

        cmbGenero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Todos", "Accion", "Comedia", "Drama", "Sci-fi", "Suspenso", "Terror" }));
        jPanel2.add(cmbGenero);

        jLabel2.setText("Genero");
        jPanel2.add(jLabel2);

        jButton1.setText("Salir");
        jButton1.addActionListener(miControl);
        jPanel2.add(jButton1);

        getContentPane().add(jPanel2, java.awt.BorderLayout.NORTH);

        jPanel1.setLayout(new java.awt.BorderLayout());

        tblMovies.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblMovies);

        jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_btnBuscarActionPerformed
    
    /**
     * @param args the command line arguments
     */
    
    public void metodo(){
        Conexion con = new Conexion("jdbc:odbc:DSNblockbuster","sa","sadb");
        String query = "SELECT Titulo, Genero, Cantidad FROM Peliculas WHERE Titulo like '%" + txtTitle.getText() + "%'";
        if(cmbGenero.getModel().getSelectedItem().toString() != "Todos"){
            query += " and Genero like '%" + cmbGenero.getModel().getSelectedItem().toString() +"%'";
        }
        tblMovies.setModel(con.executeQuery(query));
        if (tblMovies.getModel().getRowCount() == 0)
            System.out.println("No se encontraron registros...");
    }
    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame.setDefaultLookAndFeelDecorated(true);
                JDialog.setDefaultLookAndFeelDecorated(true);
                new VistaCliente().setVisible(true);
            }
            
          //  JDialog.setDefaultLookAndFeelDecorated(true);
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private javax.swing.JComboBox cmbGenero;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JTable tblMovies;
    private javax.swing.JTextField txtTitle;
    // End of variables declaration//GEN-END:variables
    
}
